/**
 * Paleta de Elementos
 *
 * @this {UIPalette}
 * @version
 */

function UIPalette() {

    /**
     * Variaveis
     */

    /**
     * Inicializa o objeto da classe
     */
    this.init = function() {

        var oSelectionPushButton = new YAHOO.widget.Button("selectionpushbutton");
        oSelectionPushButton.subscribe("click", function(evt){

            UIInstance.getUIPaletteInstance().onAddElement(EElementType.eNone);
        });

        var oRemoveElementPushButton = new YAHOO.widget.Button("removeelementpushbutton");
        oRemoveElementPushButton.subscribe("click", function(evt){

            UIInstance.getUIPaletteInstance().onRemoveElement();
        });

        var oPutToTopPushButton = new YAHOO.widget.Button("puttotoppushbutton");
        oPutToTopPushButton.subscribe("click", function(evt){

            UIInstance.getUIPaletteInstance().onReplaceElement(EGeneralTypes.eSVGPositionTop);
        });

        var oPutToBottomPushButton = new YAHOO.widget.Button("puttobottompushbutton");
        oPutToBottomPushButton.subscribe("click", function(evt){

            UIInstance.getUIPaletteInstance().onReplaceElement(EGeneralTypes.eSVGPositionBottom);
        });
        
        var oImageElementPushButton = new YAHOO.widget.Button("imageelementpushbutton");
        oImageElementPushButton.subscribe("click", function(evt){

            UIInstance.getUIPaletteInstance().onAddElement(EElementType.eTImage);
        });

        var oLabelElementPushButton = new YAHOO.widget.Button("labelelementpushbutton");
        oLabelElementPushButton.subscribe("click", function(evt){

            UIInstance.getUIPaletteInstance().onAddElement(EElementType.eTLabel);
        });

        new YAHOO.widget.Tooltip("ttbtnRemove", {
            context:"removeelementpushbutton",
            text:"Remover elemento"
        });
        new YAHOO.widget.Tooltip("ttbtnPutToTop", {
            context:"puttotoppushbutton",
            text:"Trazer elemento para frente"
        });
        new YAHOO.widget.Tooltip("ttbtnPutToBottom", {
            context:"puttobottompushbutton",
            text:"Enviar elemento para tras"
        });
        new YAHOO.widget.Tooltip("ttbtnImage", {
            context:"imageelementpushbutton",
            text:"Imagem"
        });
        new YAHOO.widget.Tooltip("ttbtnLabel", {
            context:"labelelementpushbutton",
            text:"Rotulo"
        });
    }

    /**
     * Funcoes
     */
    this.onAddElement = function(elementType) {
        var oLayoutProject = ModelInstance.getLayoutProject();
        if(oLayoutProject.projectIsOpened()) {
            UIInstance.getUIMapLayoutAreaInstance().setElementTypeToDraw(elementType);
        }
    }

    this.onRemoveElement = function() {
        var oLayoutProject = ModelInstance.getLayoutProject();
        if(oLayoutProject.projectIsOpened()) {
            UIInstance.getUIMapLayoutAreaInstance().onRemoveSVGElement();
        }
    }

    this.onReplaceElement = function(position) {
        var oLayoutProject = ModelInstance.getLayoutProject();
        if(oLayoutProject.projectIsOpened()) {
            UIInstance.getUIMapLayoutAreaInstance().onReplaceSVGElement(position);
        }
    }

    /**
     * Chamada do inicializador da classe
     */
    this.init();
}

